package com.houdoudou.customer.common;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

import android.app.AlertDialog;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;

public class CommonFunction {

public static	SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmss");
	
	public  static void   alert(Context context,String title,String message) {
	    Dialog dialog = new AlertDialog.Builder(context).setTitle(title)
	            .setMessage(message)
	            .setPositiveButton("确定", new DialogInterface.OnClickListener() {
	                public void onClick(DialogInterface dialog, int which) {
	                   
	                }
	            }).create();
	    dialog.show();
	}
	
	public static boolean isNetworkAvailble(Context context){
		Boolean netAvailble=false;
		ConnectivityManager cwjManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);  
		  if (cwjManager != null)
          {
              NetworkInfo[] info = cwjManager.getAllNetworkInfo();
              if (info != null)
                  for (int i = 0; i < info.length; i++)
                      if (info[i].getState() == NetworkInfo.State.CONNECTED)
                      {
                    	  netAvailble=true;
                    	  break;
                      }  
          }
		  
		  return netAvailble;
	}
	
	public static Date addDay(Date date, int days){		
		Calendar ca= Calendar.getInstance();
		ca.setTime(date);
		ca.add(Calendar.DATE, days);	
		return ca.getTime();
	}
	
	public static String getMyDateTime(int minuteOffset){
		String dateTime="";
		
		Date  now = new Date();
		System.out.println("current time="+ now);
		now.setMinutes(now.getMinutes()+minuteOffset);	
		System.out.println("current time after offset ="+ now);
		SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmss");
		dateTime=dateFormat.format( now ); 
		System.out.println("current time after offset in myfortmat ="+ dateTime);
		return dateTime;
	}
	
	public static String spellOrderStateWord(int orderState){
		String word="";
		
		
		if(orderState==1){ word="待支付";	}
		if(orderState==2){ word="待支付";	} //支付保护中
		if(orderState==3){ word="已取消";	}
		if(orderState==4){ word="已取消";	}
		if(orderState==6){ word="已取消";	}
		if(orderState==5){ word="已据单";	}
		if(orderState>=10&&orderState<20){ word="待发货";}
		if(orderState==20){ word="已发货";}
		if(orderState==21){ word="已送到";}
		if(orderState==22){ word="已收货";}
		if(orderState==23){ word="已收回";}
		if(orderState==24){ word="已丢弃";}
		return word;
	}
	public static String spellRefundStateWord(int refundState){
		String word="";
		if(refundState==1){ word="等待商家处理";	}
		if(refundState==2){ word="已退款";	} 
		if(refundState==3){ word="已退款";	}
		if(refundState==4){ word="商家拒绝";	}	
		if(refundState==5){ word="未退款";	}
		if(refundState==6){ word="退款仲裁中";	}
		if(refundState==7){ word="已退款";	}
		if(refundState==8){ word="未退款";	}
		if(refundState==9){ word="已退款";	}
		if(refundState==10){ word="退款取消";	}
		
	
		return word;
	}
	
	public static String spellRefundResultWord(int refundResult){
		String word="";
		if(refundResult==1){ word="处理中";	}
		if(refundResult==2){ word="退款成功";	} 
		if(refundResult==3){ word="退款失败";	}
		return word;
	}
	public static String spellRefundTypeWord(int type){
		String word="";
		if(type==1){ word="不想买了";	}
		if(type==2){ word="送货太迟";	} 
		if(type==3){ word="质量问题";	}
		if(type==4){ word="拒绝接单";	}
		if(type==5){ word="系统退款";	}
		return word;
	}
	
}
